<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog ms-modal-dialog" style="margin-top:50px;">
	<div class="modal-content">

		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal">
        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
      </button>
			 <h4 class="modal-title">新增培训项目信息</h4>
		</div>
		<form class="form-horizontal ms-form form-personal-info" method="POST" action="${ctx.host}/project-data/create" data-validate="true">
			<input type="hidden" name='maxPhaseCount' id="maxPhaseCount" value="0" />
			<div id="phaseDateDivHid" style="display:none">
			</div>
			<div class="modal-body">

				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span class="text-red">*</span>一级分类：</label>
					<div class="col-xs-8 pull-left">
						<select class="select2 form-control" name="firstCategory.id" data-validate="required" id="selFirstCat" tabindex="2">
							<option></option>
							<c:forEach items="${persist.trainingCategories}" var="TrainingCategory">
								<option value="${TrainingCategory.id}">${TrainingCategory.name}</option>
							</c:forEach>
						</select>
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span class="text-red">*</span>二级分类：</label>
					<div class="col-xs-8 pull-left">
						<input class="select2 form-control" name="secondCategory.id" data-validate="required" id="selSecondCat" tabindex="3" />
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span class="text-red">*</span>项目名称：</label>
					<div class="col-xs-8">
						<input type="text" class="form-control" name="name" placeholder="项目名称" data-validate="required" autocomplete="off" tabindex="4" />
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3" data-toggle="tooltip" data-placement="left" title="假如“总期数”为2，则意味着该项目被拆分成2期进行，2期针对的是同一批学员；若同一个名称的项目开展多次，每次针对不同学员，则需分开创建多个项目!"><span class="text-red">*</span>总期数&nbsp;<span class="glyphicon glyphicon-info-sign" aria-hidden="true" ></span>&nbsp;：</label>
					<div class="col-xs-8">
						<input type="text" class="form-control" id="phaseCount" name="phaseCount" value="" placeholder="期数" data-validate="required|number|min,1" autocomplete="off" tabindex="5" />
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span class="text-red">*</span>项目负责人：</label>
					<div class="col-xs-8 pull-left">
						<input class="select2 form-control" name="projectLead" id="projectLead" data-validate="required" tabindex="7">
					</div>
				</div>
				<c:if test="${currentPrincipal.departmentId == null}">
					<div class="form-group  ms-form-group">
						<label class="control-label col-xs-3"><span class="text-red">*</span>事业部：</label>
						<div class="col-xs-8 pull-left">
							<select class="select2 form-control" name="department.id" data-validate="required" id="selDepartment" tabindex="7">
								<option></option>
								<c:forEach items="${persist.deparments}" var="department">
                                   <c:if test="${department.name != '业务系统账户'}">
                                     <option value="${department.id}">${department.name}</option>
                                   </c:if>
								</c:forEach>
							</select>
						</div>
					</div>
				</c:if>
				<c:if test="${currentPrincipal.departmentId != null}">
					<div class="form-group  ms-form-group">
						<label class="control-label col-xs-3"><span class="text-red">*</span>事业部：</label>
                        <input type="hidden" name="department.id" value="${currentPrincipal.departmentId}">
						<p class="form-control-static">${persist.organize(currentPrincipal.departmentId).name}</p>
					</div>
				</c:if>
			</div>

			<div class="modal-footer">
				<button type="submit" class="btn btn-shadow-success btn-shadow umu-btn">保存并进入详情设置</button>
				<button type="button" class="btn btn-shadow-default btn-shadow umu-btn" data-dismiss="modal">取消</button>
			</div>
		</form>

	</div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
		$('select[name="department.id"]').select2({
			theme: "classic",
			placeholder: '请选择事业部',
			minimumResultsForSearch: 1,
			allowClear: true
		});
		$('#projectLead').select2({
			placeholder: '请选择项目负责人',
			minimumResultsForSearch: 1,
			minimumInputLength: 2,
			allowClear: true,
			ajax: {
				type: 'GET',
				url: function(params) {
					console.log(params)
					return window.__CTX__.root + '/trainees/select-search?query=' + params
				},
				dataType: 'json',
				delay: 1500,
				results: function(response, page, i) {
					console.log(page)
					console.log(i)
					if(response.code == '0' || response.code == 0) {
						return {
							results: response.data.trainees
						}
					} else {
						return null;
					}
				},
				cache: true
			}

		});
	})
</script>